<template>
  <div style="width: 300px; height: 300px;margin: 0 auto;">
    userName:<input v-model="userName"/>
    <button @click="login">login</button>
  </div>

</template>
<script setup lang="ts">
import { useLocalUserStore } from '@/stores/localUser';
import { reqSuccess } from '@/utils';
import {ref} from 'vue'
import {useRouter} from 'vue-router'

const router = useRouter()

const localUser = useLocalUserStore()
const userName = ref('')


const login = () => {
    localUser.login(userName.value).then(res => {
      const data = res.data
      if(reqSuccess(data.code)) {
        localUser.setUser({
            userName:userName.value
        })
        router.push('/')
      }else {
        console.log('login faild');
      }
    })
}


</script>